package com.arsn.myf.resource.controller;

import com.arsn.myf.common.util.result.Func;
import com.arsn.myf.common.util.result.R;
import com.arsn.myf.resource.entity.Attach;
import com.arsn.myf.resource.service.AttachService;
import com.arsn.myf.resource.vo.AttachVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.wildfly.common.annotation.NotNull;
import java.util.Arrays;

/**
 * 附件控制层
 * @author zhongrj
 * @since 2022-10-11
 */
@RestController
@RequestMapping("/attach")
@Api(value = "附件", tags = "附件")
public class AttachController {
    
    @Autowired
    private AttachService attachService;
    
    
    /**
     * 查询附件的分页数据
     * @param page
     * @param attach
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询附件的分页数据")
    public R list(Page<Attach> page, Attach attach){
        return R.data(attachService.page(page,new QueryWrapper<>(attach)));
    }


    /**
     * 自定义查询附件的分页数据
     * @param page
     * @param attach
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "自定义查询附件的分页数据")
    public R page(Page<AttachVO> page, AttachVO attach){
        return R.data(attachService.selectPageAttachList(page,attach));
    }

    /**
     * 附件详情信息
     * @param attach
     * @return
     */
    @GetMapping("/detail")
    @ApiOperation(value = "附件详情信息")
    public R detail(Attach attach){
        return R.data(attachService.getOne(new QueryWrapper<>(attach)));
    }


    /**
     * 附件新增
     * @param attach
     * @return
     */
    @PostMapping("/save")
    @ApiOperation(value = "附件新增")
    public R save(@RequestBody Attach attach){
        return R.status(attachService.save(attach));
    }

    /**
     * 附件修改
     * @param attach
     * @return
     */
    @PostMapping("/update")
    @ApiOperation(value = "附件修改")
    public R update(@RequestBody Attach attach){
        return R.status(attachService.updateById(attach));
    }


    /**
     * 删除,批量删除
     * @param ids
     * @return
     */
    @PostMapping("/remove")
    @ApiOperation(value = "删除,批量删除")
    public R remove(@NotNull String ids){
        return R.status(attachService.removeByIds(Func.stringToLong(Arrays.asList(ids.split(",")))));
    }

}
